/*----------------------------------------------------------------------------------------------*/
/*
    / 2021-3-2 17:27 一天工作结束 来一道 快排
    / 快速排序
    / 递归实现，记得flag赋值后把它从原数组里剔除，不然会崩掉
*/
 /*----------------------------------------------------------------------------------------------*/
let qSort = (arr) => {
    if (arr.length < 1) {
        return arr;
    }
    let right = [], left = [], index = Math.floor(arr.length / 2), flag = arr.splice(index, 1)[0];
    arr.map((val, idx) => {
        if (val < flag) {
            right.push(val);
        } else {
            left.push(val);
        }
    })
    return qSort(right).concat([flag], qSort(left));
}

let arr = [1,10,2,4,5,3,7,8,6,9];
console.log(qSort(arr))

/*----------------------------------------------------------------------------------------------*/